package com.t.bricks.bussiness.controller.leaveword;

import io.swagger.annotations.Api;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.t.bricks.bussiness.model.leaveword.HearerInfo;
import com.t.bricks.bussiness.model.leaveword.LeaveWordInfo;
import com.t.bricks.bussiness.service.leaveword.LeaveWordService;
import com.t.bricks.model.MsgEmity;
import com.t.bricks.utils.function.ip.IpUtil;

@RestController
@Api(value = "留言板", tags = { "辅助系统-留言板操作接口" })
@RequestMapping("/leave/word/")
public class LeaveWordController {

	/**
	 * 留言板业务实现类
	 */
	@Autowired
	private LeaveWordService leaveWordService;
	
	/**
	 * 新增留言
	 * @param request
	 * @param leaveWordInfo
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST, RequestMethod.GET}, value="/add")
	public MsgEmity addLeaveWord(HttpServletRequest request, LeaveWordInfo leaveWordInfo) {
		String ip = IpUtil.getIpAddr(request.getHeader("x-forwarded-for"), request.getHeader("Proxy-Client-IP"), request.getHeader("WL-Proxy-Client-IP"), request.getRemoteAddr());
		return leaveWordService.addLeaveWord(leaveWordInfo, ip);
	}
	
	/**
	 * 删除留言
	 * @param sSign
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST, RequestMethod.GET}, value="/del")
	public MsgEmity delLeaveWord(String sSign) {
		return leaveWordService.delLeaveWord(sSign);
	}

	/**
	 * 按名称查找留言
	 * @param sName
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST, RequestMethod.GET}, value="/find/name")
	public MsgEmity findByName(String sName) {
		return leaveWordService.findByName(sName);
	}

	/**
	 * 显示所有留言
	 * @param
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST, RequestMethod.GET}, value="/find/all")
	public MsgEmity findAll() {
		return leaveWordService.findAll();
	}

	/**
	 * 添加听众
	 * @param hearerInfo
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST, RequestMethod.GET}, value="/add/hearer")
	public MsgEmity addHearer(@RequestBody HearerInfo hearerInfo) {
		return leaveWordService.addHearer(hearerInfo);
	}

	/**
	 * 删除听众
	 * @param sName
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST, RequestMethod.GET}, value="/del/hearer")
	public MsgEmity delHearer(String sName) {
		return leaveWordService.delHearer(sName);
	}

}
